package com.yn.front.driver;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yn.common.model.zy.TCareforInfoDO;
import com.yn.common.page.BasePage;
import com.yn.common.request.driver.CareforRequest;
import com.yn.common.response.sc.BaseResult;
import com.yn.service.zy.TCareforInfoService;
import com.yn.service.zy.model.dto.TCareforInfoDTO;
import com.yn.service.zy.model.query.TCareforInfoQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/tcareforinfo/driver")
@Api(tags = "陪护相关接口")
public class CareforInfoController {
    @Autowired
    private TCareforInfoService tCareforInfoService;

    /**
     * 分页获取陪护相关接口
     * @param query
     * @param basePage
     * @return
     */
    @GetMapping("/list-page")
    @ApiOperation("分页获取陪护相关接口")
    public BaseResult listPage(TCareforInfoQuery query, BasePage basePage){
        IPage<TCareforInfoDO> tCareforInfoDOIPage = tCareforInfoService.listPage(query,basePage);

        return BaseResult.success(tCareforInfoDOIPage.convert(TCareforInfoDTO::transform));
    }

    /**
     * 获取陪护详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    @ApiOperation("获取陪护详情")
    public BaseResult info(@RequestParam(value = "id",required = true)
                           @NotNull(message = "请选择")
                           @ApiParam(value = "主键id",required = true) Integer id){
		TCareforInfoDO tCareforInfo = tCareforInfoService.getById(id);

        return BaseResult.success(TCareforInfoDTO.transform(tCareforInfo));
    }

    /**
     * 添加陪护人员
     * @param request
     */
    @PostMapping("/save")
    @ApiOperation(value = "添加陪护人员")
    public BaseResult<String> save(@RequestBody @Validated CareforRequest request){
        tCareforInfoService.saveCarefor(request);
        return BaseResult.success();
    }
}
